Tools.h++ example program

From here, you can also access:

/*
Here's an example that demonstrates use of dates, times, time 
calculations, time zones, regular expressions, and internationalization 
features.  It solves the following problem:

Imagine you have scheduled a trip form New York to Paris.  You will 
leave New York on March 31, 1995 at 11:00 PM.  What will the clock 
show in Paris when you arrive?
*/

#include <iostream.h>
#include <rw/locale.h>
#include <rw/rwdate.h>
#include <rw/rwtime.h>
#include <rw/cstring.h>
#include <rw/regexp.h>

int main (int argc, char** argv)
{
// Set the "preferred" locale as the global default:
RWLocale::global (new RWLocaleSnapshot(""));

//Construct time zones for New York and Paris:
RWZoneSimple newYorkZone (RWZone::USEastern, RWZone::NoAm);
RWZoneSimple parisZone( RWZone::Europe,  RWZone::WeEu);

// The flight is about 7 hours long:
RWTime leaveNewYork (RWDate (31, 03, 1995), 23,00,00, newYorkZone);
RWTime arriveParis (leaveNewYork + long(7 * 3600));

// Let's construct an announcement string...
RWCString announce = (argc > 1) ?
  argv [1] :  "Arrive in Paris on %T, local time.";

// ... and substitute the arrival time into it:
RWCRegexp pattern ("%T");
announce (pattern) = arriveParis.asString ('c', parisZone);
cout << announce << endl;
return 0;
}

When run this way (in the U.S.):

$ arrival

the program displays:

Arrive in Paris on Sat Apr 01 13:00:00 1995, local time.

When run this way (in France, perhaps):

$ LANG=fr arrival "Arrive au Paris `a %T, heure local."

the program displays:

Arrive au Paris `a sam 1avr 95, 13:00:00 MET DST, heure local.

The correct time appears even though your flight:


© Copyright 1995, Rogue Wave Software, Inc.